 	
	*Set constants
	clear all
	set more off
	global sysdate: display %tdCCYY-NN-DD date(c(current_date), "DMY")
	disp "$sysdate" //date is YMD with hyphens between fields
	eststo clear
	
	
	global input_dir "data_location"
	
	global output_dir "output_location"
	
	global code_dir "project_directory"
	
		
	set scheme lean2
	graph set window fontface "Garamond"
	
	global dosemin 0.2
	global rand_seed 974093
	
	do "$code_dir\permutation programs.do"
	
	global stars "star"
	
	
	* MAIN GLOBALS
	global nothreatvars nothreat_cycle3
	global ntvars_23 $nothreatvars
	
	
	global feedbackvars postconf_p1 postconf_p2 postconf_m1 postconf_m2 
	global experiencevar exp_capped exp_capped_squared
	global tdemovars tblack thisp twhite tasian taiak i.tage_adj_cat i.entryyear i.step
	global sdemovars i.male i.black i.hisp i.othrace i.lep_dv i.sped_dv i.frpl_dv 
	global sdemovars_race i.male i.black i.hisp i.othrace
	global sdemovars_other i.lep_dv i.sped_dv i.frpl_dv 
	global prevvars math_std_t read_std_t class_math_std_t class_read_std_t
	global yeardosevar i.year_dose_cat
	global gradevar i.grade_c
	
	global probvarsother haz_unif_p2 haz_unif_m1 haz_unif_m2 
	global haz_var_indicator_other "uniform" 
		
	global probvars haz_p2 haz_m1_true haz_m2 
	global haz_var_indicator "kernel" 	
	
		** store globals to restore later --> this way only set once here
		global tmpnothreatvars $nothreatvars
		global tmpfeedbackvars $feedbackvars
		global tmptdemovars $tdemovars
		global tmpsdemovars $sdemovars
		global tmpsdemovars_race $sdemovars_race
		global tmpsdemovars_other $sdemovars_other
		global tmpprevvars $prevvars
		global tmphazvarindicator $haz_var_indicator
		global tmphazvarindicatorother $haz_var_indicator_other
		global tmpprobvarsother $probvarsother
		global tmpprobvars $probvars
		global tmpexperiencevar $experiencevar
		global tmpntvars23 $ntvars_23
	

	
	
	*=========================================================*
	* Load and Limit Data -- create frames
	*=========================================================*
	use "$input_dir\students_threat.dta", clear	
	frame rename default original_data
	
		tostring sch_id, g(sch_id_str)
		tostring year, g(year_str)
		g schXXyear = sch_id_str + "-" + year_str
		
		* need to add the average class performance
		bysort id year: egen totalm = total(math_std_t)
		bysort id year: egen totalr = total(read_std_t)
		bysort id year: egen countm = count(math_std_t)
		bysort id year: egen countr = count(read_std_t)
		bysort id year: gen class_math_std_t = (totalm-math_std_t)/(countm-1)
		bysort id year: gen class_read_std_t = (totalr-read_std_t)/(countr-1)
		drop totalm totalr countm countr
	
		*** *** *** ***
	
	do "$code_dir\00_generateFrames.do"
	
	
		global framename "grades_45"
		frame change ${framename}_no_exp0
		global output_dir "C:\Users\aaron.phipps\OneDrive - West Point\Projects\Live Projects\No threat time\analysis\output\Version 07"


	*=========================================================*
	* Summary Stats and Figures
	*=========================================================*
	
	* Table 1 -- all sum stats
		do "$code_dir\_Table_01_CompleteSummaryStats.do"
		
	
	*=========================================================*
	* Balance Checks
	*=========================================================*
	
	
	* Table A1: Balance table of treatment for students
		global experiencevar experience experience_squared
		global sdemovars male black hisp othrace lep_dv sped_dv frpl_dv
		global discipline
		global prevvars read_std_t math_std_t 
		global sdemovars_race male black hisp othrace
	
		do "$code_dir\_Table_13.do"
	
	
	* Table A2: Balance table of treatment for teachers
		global experiencevar experience experience_squared
		global prevvars tlf_L
		global prevvars_2 he_lastyear me_lastyear
		global tdemovars tblack thisp tasian
		
		do "$code_dir\_Table_15.do"

	
		
		
		*=======================================================================================*
		* Results and Robustness:  (and associated appendix tables)
		*=======================================================================================*
		
		// reset globals
		global nothreatvars $tmpnothreatvars 
		global feedbackvars $tmpfeedbackvars
		global tdemovars $tmptdemovars 
		global sdemovars $tmpsdemovars 
		global sdemovars_race $tmpsdemovars_race 
		global sdemovars_other $tmpsdemovars_other 
		global prevvars $tmpprevvars 
		
		global probvars $tmpprobvars
		global haz_var_indicator $tmphazvarindicator
		global probvarsother $tmpprobvarsother
		global haz_var_indicator_other $tmphazvarindicatorother
		
		global experiencevar $tmpexperiencevar
		
		
		
		***************************
		* MAIN RESULTS and variations
		*****************************
	
		
		
			global reps = 1000
			global ricluster = 1
			global skip3rdcolumn = 0
			global multipletreats = 0
		
	
	
		* Table 2
			global multipletreats = 0
			global do_ri "YES"
			global tablenum "Table_16"
			do "$code_dir\_Table_16.do"
			
			
		* binscatter plots (Figure 2)
			do "$code_dir\_Figure_binscatterPlots.do"
		
			
			
			
		* Table A04 - robustness to experie4nce specification  ---> no global changes in table code
			* --  need to change variable selection within the do-file
			global do_ri "NO"
			do "$code_dir\_Table_A01_ExperienceRobustness.do"
			
		* Table A05 - results by grade  ---> no global changes in table code
			global do_ri = "NO"
			global nothreatvars c.nothreat_cycle3#i.grade_c 
			global ntvars_23 $nothreatvars
			global tablenum "Table_A05"
			do "$code_dir\_Table_16.do"
			// change it back! --->
			global nothreatvars $tmpnothreatvars
			global ntvars_23 $tmpntvars23
			
			

		* Table 4 (Panels A and B)
			* --  need to change variable selection within the do-file
			global experiencevar exp_capped exp_capped_squared
			do "$code_dir\_Table_18_Suspensions.do"
			do "$code_dir\_Table_19_effects on suspension by date.do"
			global experiencevar $tmpexperiencevar

		
		* Figure 4
		* --  need to change variable selection within the do-file
			do "$code_dir\_Table_24_IndividualTLF_posttestM2.do" 
		

	* Robustness:
		
		* Table 3
			* --  need to change variable selection within the do-file
			global nothreatvars posttest_ntc4
			do "$code_dir\_Table_21_posttest.do"
			global nothreatvars $tmpnothreatvars
		
		* Table A03
			* --  need to change variable selection within the do-file
			do "$code_dir\_Table_22_psacalc.do"


		
	* Figure 3
		do "$code_dir\_Figure_VariationInProb.do"
		
		
	










	
	